﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetLable();
        }
    }

    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        //String username = Login1.UserName;
        //String password = Login1.Password;
        //bool remember = Login1.RememberMeSet;
        //int userID;
        //HttpCookie authCookie = LoginService.Authenticate(username, password, out userID);
        //if (authCookie != null)
        //{
        //    // Store username in session
        //    Session.Add(WebsiteConstant.USER_NAME, username);
        //    // Add the cookie to the outgoing cookies collection.
        //    Response.Cookies.Add(authCookie);
        //    // Redirect the user to the originally requested page
        //    Response.Redirect(FormsAuthentication.GetRedirectUrl(username, remember));
        //}
    }
    protected void SetLable()
    {
        //Login1.UserNameLabelText = "Tên đăng nhập";
        //Login1.PasswordLabelText = "Mật khẩu";
        //Login1.FailureText = "Đăng nhập thất bại";
        //Login1.CreateUserText = "Đăng kí tài khoản";
        //Login1.PasswordRecoveryText = "Lấy lại mật khẩu";
    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        String username = this.txtUserName.Text;
        String password = this.txtPassWord.Text;
        bool remember = this.cbxRememberPassword.Checked;
        int userID;
        HttpCookie authCookie = LoginService.Authenticate(username, password, out userID);
        if (authCookie != null)
        {
            // Store username in session
            Session.Add(WebsiteConstant.USER_NAME, username);
            // Add the cookie to the outgoing cookies collection.
            Response.Cookies.Add(authCookie);
            // Redirect the user to the originally requested page
            Response.Redirect(FormsAuthentication.GetRedirectUrl(username, remember));
        }
    }
}